Complete Design-2 assignment - #2494
Conversation
Remove older implementation and add java implementation for HashSet and Queue using Stacks
Remove older implementation and add java implementation for HashSet and Queue using Stacks - Updated author as it is configured wrongly
Implement Queue using Stacks (ImplementQueueUsingStacks.java)Strengths:
Areas for improvement:
VERDICT: PASS Design HashMap (ImplementHashMap.java)E attempted to use double hashing with a 2D array approach, which is a valid technique. However, there are several critical bugs in the implementation:
Let me trace through more carefully:
Now let's check the collision case:
Wait, but what about key=1001 and key=2001?
Hmm, actually the double hashing might work for distinct keys because the combination of primary and secondary hash is unique for each key... wait, no. Consider key=1 and key=1001:
These are different positions, so no collision. But what about key=1000 and key=2000?
Different positions. What about key=500 and key=1500?
Different positions. Actually, I think the double hashing approach here might work because for any two distinct keys, the pair (primary hash, secondary hash) is unique. Let me verify:
Actually, I think for any two distinct keys, the pair (key % buckets, key / bucketItems) is unique. This is because:
Wait, bucketItems = 1000 and buckets = 1000. So key = (key / 1000) * 1000 + (key % 1000). If two keys have the same quotient and remainder, they must be equal. So yes, the double hashing approach is correct in terms of avoiding collisions! But wait, there's still the issue with the sentinel values. Let me check:
But what about:
What about:
Hmm, but what about the case where value is -1 or -2?
But what if we never remove and just put -1?
Wait, the constraints say 0 <= key, value <= 10^6, so value is always >= 0. So we don't need to worry about negative values being put. But there's still a subtle issue: what if we put a value of 0, then remove it, then put a value of 0 again?
VERDICT: NEEDS_IMPROVEMENT |
Please note that I had to amend the commit after reconfiguring the author correctly. Thanks